package com.company.bookstore.entities.user_admin_module;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import org.springframework.data.annotation.Transient;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * <p>
 * 管理员表
 * </p>
 *
 * @author 吴经纶
 * @blame Android Team
 * @since 2020-08-28
 */

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName("t_admin")
public class Admin implements UserDetails {


    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    /**
     * 管理员姓名

     */
    private String adminName;
    /**
     * 密码
     */
    private String password;
    /**
     * 角色外键
     */
    private Integer fkRoleId;
    @Getter(value = AccessLevel.NONE)
    private Integer enabled;
    private Integer deleted;
    private Integer sex;


    @TableField(exist = false)
    @Transient
    private Roles roles;

    @TableField(exist = false)
    @Transient
    Collection<GrantedAuthority> power;


    @Override
    public String getUsername() {
        return adminName;
    }
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return power;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return enabled == null || enabled == 1;
    }
}
